package com.neuedu.my12306.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.neuedu.my12306.entity.StationInfo;
import com.neuedu.my12306.service.IStationInfoService;
import com.neuedu.my12306.util.SpringContextUtil;

/**
 * Servlet implementation class StationAddServlet
 */
@WebServlet("/StationAddServlet.do")
public class StationAddServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private IStationInfoService iStationInfoService = null;

    public StationAddServlet() {
        super();
        iStationInfoService = SpringContextUtil.getBean("stationService", IStationInfoService.class);
		//stationInfoService = new IStationInfoServiceImpl();
      
    }


	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		boolean ret = false;
		int id = 0;
		String stationImage = null;
		String stationName =  request.getParameter("stationName");
		String stationProvince = request.getParameter("stationProvince");
		StationInfo stationInfo = new StationInfo(id, stationName, stationProvince, stationImage);
		ret = iStationInfoService.insert(stationInfo);
		if (ret) {
			request.getSession().setAttribute("MSG", "新增成功");
		}else {
			request.getSession().setAttribute("MSG", "新增失败");
		}
		
		request.getSession().setAttribute("BACKURL", request.getContextPath() + "/StationAdminServlet.do");
		response.sendRedirect(request.getContextPath() + "/error.jsp");
	}
		
}


